package net.joneepenk.util.jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public abstract class JdbcUpdateHelper extends JdbcHelper {

	public int update(String sql, Object[] params){
		Connection conn = null;
		PreparedStatement ps = null;
		try{
			conn = getConnection();
			ps = conn.prepareStatement(sql);
			setParams(params, ps);
			long begin = System.nanoTime();
			ps.executeUpdate();
			if(log.isDebugEnabled()){
				log.debug("Update spent time: " + (System.nanoTime() - begin));
				log.debug("UPDATE SQL Executed: " + ps.toString());
			}
			return ps.getUpdateCount();
		} catch (SQLException e){
			log.warn("Exception is catched: " + e);
		} finally {
			close(conn, ps, null);
		}
		return -1;
	}
}
